package com.itheima.user.controller;

import com.itheima.user.pojo.User;
import com.itheima.user.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {
    @Value("${server.port}")
    int port;
    @Resource
    private UserService userService;

    @GetMapping("/{username}")
    public User findByUsername(@PathVariable("username") String username, HttpServletRequest request) {
        System.out.println("当前用户服务端口==>" + port);
        String name = request.getHeader("name");
        System.out.println("请求头name的值 = " + name);
        User user = userService.findByUsername(username);
        user.setEmail("当前用户服务端口==>" + port);//用来方便做负载均衡时前端展示端口号，
        return user;
    }
}
